/**
 * Copyright:Copyright(c)2014-2017
 * Company:厦门市易致达物联网科技有限公司
 * @version 1.0
 */
package shop.controller.manage.pickup;
import shop.core.common.bean.JSONResult;
import shop.core.util.KeyValueHelper;
import shop.core.Services;
import shop.core.util.MD5;
import shop.services.manage.pickup.PickupService;
import shop.services.manage.pickup.bean.Pickup;
import shop.core.BaseController;
import shop.core.RequestHolder;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**   
 * @类名称：PickupAction      
 * @创建人：Ltz   
 * @创建时间：2017-10-24 上午10:00:07      
 * @版本号：1.0
 * @描述：     
 */
@Controller
@RequestMapping("/manage/pickup/")
public class PickupAction extends BaseController<Pickup> {
    private static final Logger logger = LoggerFactory.getLogger(PickupAction.class);
    @Autowired
    private PickupService pickupService;

    private static final String page_toList = "/manage/pickup/pickupList";
    private static final String page_toEdit = "/manage/pickup/pickupEdit";

    public PickupService getService() {
        return pickupService;
    }

    private PickupAction(){
        super.page_toList = page_toList;
        super.page_toAdd = null;
        super.page_toEdit = null;
    }

    /**
     * 跳转到提货详情页面
     * @param e
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("toEditOne")
    public String toEditOne(@ModelAttribute("e") Pickup e, ModelMap model) throws Exception {
        e = getService().selectOne(e);
        switch (e.getIsSent()){
            case "1":
                e.setIsSent("待发货");
                break;
            case "2":
                e.setIsSent("待收货");
                break;
            default:
                e.setIsSent("已完成");
        }
        model.addAttribute("e", e);
        return page_toEdit;
    }

    /**
     * 删除单个提货记录
     * @param request
     * @param e
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "deleteOne", method = RequestMethod.POST)
    @ResponseBody
    public JSONResult deleteOne(HttpServletRequest request, @ModelAttribute("e") Pickup e) throws Exception {
        JSONResult jsonResult=new JSONResult();
        getService().delete(e);
        jsonResult.setMessage("success");
        return jsonResult;
    }
}
